deferred class IUP_LINEAL_BOX
-- Abstract class for linear containers.

inherit
	IUP_CONTAINER
	IUP_WIDGET_EXPAND
	IUP_WIDGET_SIZE
	IUP_WIDGET_RASTERSIZE
	IUP_WIDGET_USERSIZE
	IUP_WIDGET_WID
	IUP_WIDGET_FONT
	IUP_WIDGET_CLIENTSIZE
	IUP_WIDGET_CLIENTOFFSET
	IUP_WIDGET_POSITION
	IUP_WIDGET_MAXMIN_SIZE
	IUP_WIDGET_CHILD
	IUP_WIDGET_NAME
	IUP_WIDGET_CUSTOM_ATTRIBUTES

feature {ANY}

	-- Attributes

	set_alignment (value: STRING)
		require
			is_valid: is_valid_alignment(value)
		do
			iup_open.set_attribute(Current, "ALIGNMENT", value)
		end

	get_alignment: STRING
		-- Return the value of the alignment.
		do
			Result := iup_open.get_attribute(Current, "ALIGNMENT")
		end

	set_gap (space: INTEGER)
		-- Defines a vertical space in pixels between the children. Default: "0".
		require
			space >= 0
		do
			iup_open.set_attribute(Current, "GAP", space.to_string)
		end

	get_gap: INTEGER
		-- Return the vertical space between the children.
		local
			value: STRING
		do
			value := iup_open.get_attribute(Current, "GAP")
			Result := value.to_integer
		end

	set_cgap (space: INTEGER)
		-- Defines a vertical space between the children in the same units of 
		-- the SIZE attribute for the height. Default: "0".
		require
			space >= 0
		do
			iup_open.set_attribute(Current, "CGAP", space.to_string)
		end

	get_cgap: INTEGER
		-- Return the value of the attribute cgap.
		local
			value: STRING
		do
			value := iup_open.get_attribute(Current, "CGAP")
			Result := value.to_integer
		end

	set_ngap (space: INTEGER)
		-- Same as *GAP* but non inheritable.
		require
			space >= 0
		do
			iup_open.set_attribute(Current, "NGAP", space.to_string)
		end

	get_ngap: INTEGER
		-- Return the value of *NGAP* attribute.
		local
			value: STRING
		do
			value := iup_open.get_attribute(Current, "NGAP")
			Result := value.to_integer
		end

	set_ncgap (space: INTEGER)
		-- Same as *CGAP* but non inheritable.
		require
			space >= 0
		do
			iup_open.set_attribute(Current, "NCGAP", space.to_string)
		end

	get_ncgap: INTEGER
		-- Return the value of *NCGAP* attribute.
		local
			value: STRING
		do
			value := iup_open.get_attribute(Current, "NCGAP")
			Result := value.to_integer
		end

	set_homogeneous (state: BOOLEAN)
		-- (non inheritable): forces all children to get equal vertical space. 
		-- The space height will be  based on the highest child. Default: "NO". 
		--Notice	that this does not changes the children size, only the available 
		--space for each one of them to expand.
		do
			iup_open.set_attribute(Current, "HOMOGENEOUS", boolean_to_yesno(state))
		end

	is_homogeneous: BOOLEAN
		-- Return the state of homogeneous.
		local
			str: STRING
		do
			str := iup_open.get_attribute(Current, "HOMOGENEOUS")
			Result := yesno_to_boolean(str)
		end

	set_margin (horizontal, vertical: INTEGER)
		-- Defines a margin in pixels. Default: "0x0" (no margin).
		require
			horizontal >= 0
			vertical >= 0
		local
			margin: STRING
		do
			margin := horizontal.to_string
			margin.append_string("x")
			margin.append_string(vertical.to_string)

			iup_open.set_attribute(Current, "MARGIN", margin)
		end

	get_margin: TUPLE[INTEGER, INTEGER]
		-- Return the value of the margins.
		local
			margin: STRING
		do
			margin := iup_open.get_attribute(Current, "MARGIN")
			Result := components_of_size(margin)
		end

	set_cmargin (horizontal, vertical: INTEGER)
		-- Defines a margin in the same units of the SIZE attribute. 
		-- Default:	"0x0" (no margin).
		require
			horizontal >= 0
			vertical >= 0
		local
			margin: STRING
		do
			margin := horizontal.to_string
			margin.append_string("x")
			margin.append_string(vertical.to_string)

			iup_open.set_attribute(Current, "CMARGIN", margin)
		end

	get_cmargin: TUPLE[INTEGER, INTEGER]
		-- Return the value of the CMARGIN.
		local
			margin: STRING
		do
			margin := iup_open.get_attribute(Current, "CMARGIN")
			Result := components_of_size(margin)
		end

	set_nmargin (horizontal, vertical: INTEGER)
		-- (non inheritable): Same as MARGIN but are non inheritable.
		require
			horizontal >= 0
			vertical >= 0
		local
			margin: STRING
		do
			margin := horizontal.to_string
			margin.append_string("x")
			margin.append_string(vertical.to_string)

			iup_open.set_attribute(Current, "NMARGIN", margin)
		end

	get_nmargin: TUPLE[INTEGER, INTEGER]
		-- Return the value of the nmargin.
		local
			margin: STRING
		do
			margin := iup_open.get_attribute(Current, "NMARGIN")
			Result := components_of_size(margin)
		end

	set_ncmargin (horizontal, vertical: INTEGER)
		-- (non inheritable): Same as CMARGIN but are non inheritable.
		require
			horizontal >= 0
			vertical >= 0
		local
			margin: STRING
		do
			margin := horizontal.to_string
			margin.append_string("x")
			margin.append_string(vertical.to_string)

			iup_open.set_attribute(Current, "NCMARGIN", margin)
		end

	get_ncmargin: TUPLE[INTEGER, INTEGER]
		-- Return the value of NCMARGIN.
		local
			margin: STRING
		do
			margin := iup_open.get_attribute(Current, "NCMARGIN")
			Result := components_of_size(margin)
		end

	set_normalize_size (value: STRING)
		-- (non inheritable): normalizes all children natural size to be the 
		-- biggest natural size among them. All natural width will be set to the 
		-- biggest width, and all natural height will be set to the biggest 
		-- height according to is value. Can be NO, HORIZONTAL, VERTICAL or BOTH. 
		-- Default: "NO". Same as using IUP_NORMALIZER. 
		require
			is_valid_normalizasize(value)
		do
			iup_open.set_attribute(Current, "NORMALIZESIZE", value)
		end

	get_normalize_size: STRING
		-- Return the value of normalize size.
		do
			Result := iup_open.get_attribute(Current, "NORMALIZESIZE")
		end

	set_expand_children (state: BOOLEAN)
		do
			iup_open.set_attribute(Current, "EXPANDCHILDREN", boolean_to_yesno(state))
		end

	is_expand_children: BOOLEAN
		local
			str: STRING
		do
			str := iup_open.get_attribute(Current, "EXPANDCHILDREN")
			Result := yesno_to_boolean(str)
		end

feature {}

	is_valid_alignment (value: STRING): BOOLEAN
		deferred
		end
	
	is_valid_normalizasize (value: STRING): BOOLEAN
		do
			if value.is_equal("BOTH") or
				value.is_equal("HORIZONTAL") or
				value.is_equal("VERTICAL") or
				value.is_equal("NO") then
				Result := True
			else
				Result := False
			end
		end
	
end

-- The MIT License (MIT)

-- Copyright (c) 2016, 2017 by German A. Arias

-- Permission is hereby granted, free of charge, to any person obtaining a copy
-- of this software and associated documentation files (the "Software"), to deal
-- in the Software without restriction, including without limitation the rights
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-- copies of the Software, and to permit persons to whom the Software is
-- furnished to do so, subject to the following conditions:
--
-- The above copyright notice and this permission notice shall be included in 
-- all copies or substantial portions of the Software.
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-- SOFTWARE.
